const koajwt = require('koa-jwt');
const jwt = require('jsonwebtoken');
const JWT = Symbol('Application#jwt');

// 钉钉
const DINGDING = Symbol('Application#dingding');
const dd = require('../lib/dingding');

// 钉钉
const DTALK = Symbol('Application#dtalk');
const dtalk = require('../lib/dingtalk');

// 通用表操作
const TABLE = Symbol('Application#table');
const table = require('../lib/table');

module.exports = {
  get jwt() {
    if (!this[JWT]) {
      this[JWT] = koajwt(this.config.jwt);
      this[JWT].sign = jwt.sign;
      this[JWT].verify = jwt.verify;
      this[JWT].decode = jwt.decode;
    }
    return this[JWT];
  },
  get dd() {
    if (!this[DINGDING]) {
      this[DINGDING] = dd(this);
    }
    return this[DINGDING];
  },
  get dtalk() {
    if (!this[DTALK]) {
      this[DTALK] = dtalk(this);
    }
    return this[DTALK];
  },
  table(tableName) {
    if (!this[TABLE]) {
      this[TABLE] = table(this)
    }
    return new this[TABLE](tableName)
  },
};
